package com.wx.house.common.config;


import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;


@Configuration
@EnableSwagger2
public class Swagger2Config {

@Bean
public Docket createRestApi() {
	ParameterBuilder userTokenHeader = new ParameterBuilder();
	List<Parameter> pars = new ArrayList<>();
	userTokenHeader
			.name("authorization")
			.description("Token认证令牌")
			.modelRef(new ModelRef("string"))
			.parameterType("header")
			.required(false);
	pars.add(userTokenHeader.build());
	return new Docket(DocumentationType.SWAGGER_2)
			       .apiInfo(apiInfo())
			       .select()
			       .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
			       .paths(PathSelectors.any())
			       .build()
			       .globalOperationParameters(pars);
}

private ApiInfo apiInfo() {
	return new ApiInfoBuilder()
			       .title("稳信公寓管理")
			       .contact(new Contact("稳信科技", "http://www.9linked.com", "58428467@qq.com"))
			       .description("稳信公寓管理系统API")
			       .version("1.0")
			       .build();
}


@SuppressWarnings("all")
@Bean
UiConfiguration uiConfig() {
	return new UiConfiguration(
			null,
			"list",
			"alpha",
			"schema",
			UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS,
			true,
			true,
			60000L);
}
}
